/*
 * @(#)IdInfo.java
 * Date 2014-01-20
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package com.chrisuyehara.vista.rpc.procedures.ORWPT;

import com.chrisuyehara.vista.rpc.models.PatientIdInfo;

import com.chrisuyehara.vista.rpc.parameters.LiteralParameter;

import com.chrisuyehara.vista.rpc.procedures.AbstractRemoteProcedure;

import com.chrisuyehara.vista.rpc.util.VistaDateUtil;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;


/**
 * Class description
 *
 *
 * @version        v1.0, 2014-01-20
 * @author         Jim Horner
 */
public class IdInfo extends AbstractRemoteProcedure {

    /**
     * Constructs ...
     *
     *
     * @param dfn
     */
    public IdInfo(String dfn) {

        super("ORWPT ID INFO");
        addParameter(new LiteralParameter(dfn));
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public PatientIdInfo getPatientIdInfo() {

        PatientIdInfo result = null;

        String resp = getResponse();

        if (StringUtils.isNotBlank(resp)) {

            result = new PatientIdInfo();

            String[] fields = StringUtils.splitPreserveAllTokens(resp, "^");

            if (ArrayUtils.isNotEmpty(fields) && (fields.length == 8)) {

                result.setSsn(fields[0]);
                result.setDateOfBirth(VistaDateUtil.parseVistaDate(fields[1]));
                result.setGender(fields[2]);
                result.splitName(fields[7]);
            }
        }

        return result;
    }
}
